<?php
/**
 * Nombre: VisorLogs.php
 * Autor: Juan José Muñiz Juarez
 * Fecha: 19/04/2012, 13:06:24
 * Version: 1.0
 * Descripción:  
 */
if ( ! defined ( "LOG_RUTA_ARCHIVOS" ) )
   {
      include "../../config/Constantes.php";
   }
$log = LOGGER_RUTA_ARCHIVOS . "/log1.log";

echo $log;
//echo "[" .$_POST[ "accion" ] . "][ " . $_POST[ "eliminar" ] . " ]";
if ( isset( $_POST[ "eliminar" ] ) )
  {
     if ( $_POST[ "eliminar" ] == "1" )
       {
          unlink( $log );
       }
  }

?>


      <meta charset="utf-8">
      <!--<title>Visor de logs</title>-->
      <!--  <link rel="stylesheet" media="screen" href="<?php echo CSS_RUTA_BASE . "/general.css"?>" />-->
      <!--<link rel="stylesheet" media="screen" href="<?php echo CSS_RUTA_BASE . "/logs.css"?>" />-->
      <style>
         * {
             font-size : 12px;
             
         }
         .log {
    
             border : 1px solid black;
             height: 350px;
             overflow : scroll;
             overflow-x : scroll;
             overflow-y : scroll;
         }
         
         table {
    
             border : 1px solid #008800;
             align : center;          
             border-left : 1px;
             border-right : 1px;   
             width : 1px auto;
         }
      </style>
      <script type="text/javascript">
         function eliminarLogs()
           {
             document.getElementById( "eliminar" ).value = "1";
      	     document.getElementById( "forma" ).submit();
           }
   
         function recargarLogs()
           {
      	     document.getElementById( "forma" ).submit();
           }
      </script>
   </head>
   
   <body>     
      <form id="forma" method="post">
         <input type="hidden" id="eliminar" name="eliminar" />
         <input type="button" name="accion" id="accion" value="Eliminar" onclick="eliminarLogs()"/>
         <input type="button" name="recargar" id="recargar" value="Recargar" onclick="recargarLogs()" />
         <div class="log">
            <table border="1">
               <colgroup>
                  <col width="10%" /><col width="15%" /><col width="15%" />
                  <col width="10%" /><col width="15%" /><col width="25%" />
                  <col width="10%" />
               </colgroup>
               <tr>
                  <th>Nivel</th>
                  <th>Clase</th>
                  <th>Metodo</th>
                  <th>Linea</th>
                  <th>Fecha</th>
                  <th>Descripcion</th>
                  <th>Sesion Usuario</th>
               </tr>
               <?php      
                 if ( file_exists( $log ) )
                   {
                     $file = fopen ( $log, "rb" );
                     $delimitador = "~";
                     $total_columnas = 6;
                     $contador = 0;
                     
                     if ( $file )
                        do
                           {
                              $line = fgets ( $file );
                              
                              if ( $line )
                                {
                                   echo "<tr>";
                                   
                                   $datos = explode( $delimitador , $line );                                  
                                   
                                   if ( $datos )
                                    {
                                       if ( is_array( $datos ) )
                                         {
                                            $contador = 0;
                                            
                                            foreach( $datos as $dato )
                                              {
                                                 echo "<td";
                                                 
                                                 $div = "";
                                                 if ( !( $contador == $total_columnas - 1 ) )
                                                   {
                                                      echo " align='center'";
                                                   }
                                                 else
                                                   {
                                                      $div = "<div class='info_log'>";
                                                   }  
                                                   
                                                 echo ">";
                                                 
                                                 if ( $div )
                                                   {
                                                      echo $div;
                                                   }    
                                                   
                                                 echo utf8_decode( $dato );
                                                 
                                                  if ( $div )
                                                   {
                                                      echo "</div>";
                                                   }  
                                                 echo "</td>";
                                                 
                                                 $contador++;
                                              }
                                         }
                                       else
                                         {
                                            echo "<td colspan='$total_columnas'>";                                            
                                            echo $datos;
                                            echo "</td>";
                                         }  
                                    }
                                    
                                    echo "</tr>";  
                                }
                           }
                        while ( ! feof ( $file ) );
                     fclose ( $file );
                   }
                   
                ?>
             </table>   
         </div>
      
      
          <input type="button" name="recargar2" id="recargar2" value="Recargar" onclick="recargarLogs()" />
       </form>
   
    
    